package com.shop.loan.util;

import cn.hutool.crypto.digest.MD5;
import org.springframework.util.StringUtils;

public class PasswordUtil {

    private static final String key = "olpsasn.ppa.rd26.24@asyun.10023_";

    /**
     * 获取密文
     *
     * @param password
     * @return
     */
    public static String getEncrypt(String password) {
        return MD5.create().digestHex(key + "_" + password);
    }

    /**
     * 验证密码是否正确
     *
     * @param password
     * @param encrypt
     * @return
     */
    public static boolean checkPassword(String password, String encrypt) {
        if (!StringUtils.hasText(encrypt)) {
            return false;
        }
        if (MD5.create().digestHex(key + "_" + password).trim().equals(encrypt)) {
            return true;
        }
        return false;
    }

}
